# Train KRR on random WA (size matched to all AA, see `KRR_allAA_vs_randWA.md`)

## Create `sub_fold` structure for random WA subjects

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
ABCD_create_subfold_randWA(...
    fullfile(proj_dir, 'scripts', 'lists', 'subjects_pass_rs_pass_pheno.txt'), ...
    fullfile(proj_dir, 'scripts', 'lists', 'behavior_list.txt'), ...
    fullfile(proj_dir, 'mat', 'matchANDsplit', '20200719'), ...
    '_pass_rs_pass_pheno')
```

## ------ KRR: regress age, sex, FD, DVARS, ICV, parental education from behaviors and RSFC ------

### Run KRR only on random WA

```bash
cd ../KRR
./ABCD_KRR_reg_AgeSexMtIcvPEduc_y_FC_randWA.sh
```

### Test the random-WA trained model with matched WA subjects

```bash
proj_dir=/home/jingweil/storage/MyProject/fairAI/ABCD_race
../KRR/ABCD_KRR_test_randWAmodel_on_matchedWA.sh -model_dir \
  $proj_dir/models/KRR/20200721/reg_AgeSexMtIcvPEduc_y_FC_randWA -cfds_X_ls \
  /home/jingweil/storage/MyProject/fairAI/ABCD_race/scripts/lists/confounds_list.txt
```

### Test the random-WA trained model with the matched AA subjects

```bash
proj_dir=/home/jingweil/storage/MyProject/fairAI/ABCD_race
../KRR/ABCD_KRR_test_randWAmodel_on_matchedAA.sh -model_dir \
  $proj_dir/models/KRR/20200721/reg_AgeSexMtIcvPEduc_y_FC_randWA -cfds_X_ls \
  /home/jingweil/storage/MyProject/fairAI/ABCD_race/scripts/lists/confounds_list.txt
```

### Using model trained on WA, compare accuracy between matched AA and matched WA

1. metric: predictive COD

    Permutation test

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_PermTest_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_FC_randWA'), ...
        'matchedAA', 'AA', 'matchedWA', 'matchedWA', [], 'predictive_COD', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'pCOD_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA.mat'))

    % behaviors that are predictable in the whole-population model
    ABCD_KRR_PermTest_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_FC_randWA'), ...
        'matchedAA', 'AA', 'matchedWA', 'matchedWA', ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y_FC', 'lists', 'pCOD_predictable.txt'), ...
        'predictive_COD', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'pCOD_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA_predictable_WholepopModel.mat'))
    ```

    Plotting

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whisker_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_FC_randWA'), ...
        'matchedAA', 'matchedWA', [], [], 'predictive_COD', ...
        'Matched AA vs WA (model trained on random WA)', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), ...
        'pCOD_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'pCOD_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA.mat'))

    % behaviors that are predictable in the whole-population model
    ABCD_KRR_whisker_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_FC_randWA'), ...
        'matchedAA', 'matchedWA', ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y_FC', 'lists', 'pCOD_predictable.txt'), ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y_FC', 'lists', 'pCOD_predictable_colloquial.txt'), ...
        'predictive_COD', ...
        'Matched AA vs WA (model trained on random WA)', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), ...
        'pCOD_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA_predictable_WholepopModel', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'pCOD_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA_predictable_WholepopModel.mat'))
    ```

2. metric: Pearson's correlation

    Permutation test

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_PermTest_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_FC_randWA'), ...
        'matchedAA', 'AA', 'matchedWA', 'matchedWA', [], 'corr', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'corr_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA.mat'))

    % behaviors that are predictable in the whole-population model
    ABCD_KRR_PermTest_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_FC_randWA'), ...
        'matchedAA', 'AA', 'matchedWA', 'matchedWA', ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y_FC', 'lists', 'corr_predictable.txt'), ...
        'corr', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'corr_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA_predictable_WholepopModel.mat'))
    ```

    Plotting

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whisker_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_FC_randWA'), ...
        'matchedAA', 'matchedWA', [], [], 'corr', ...
        'Matched AA vs WA (model trained on random WA)', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), ...
        'corr_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'corr_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA.mat'))

    % behaviors that are predictable in the whole-population model
    ABCD_KRR_whisker_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_FC_randWA'), ...
        'matchedAA', 'matchedWA', ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y_FC', 'lists', 'corr_predictable.txt'), ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y_FC', 'lists', 'corr_predictable_colloquial.txt'), ...
        'corr', ...
        'Matched AA vs WA (model trained on random WA)', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), ...
        'corr_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA_predictable_WholepopModel', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'corr_randWAmodel_reg_AgeSexMtIcvPEduc_y_FC_test_matchedAAvsWA_predictable_WholepopModel.mat'))
    ```

### Plot chord diagrams of model-learned brain-behavioral association

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
bhvr_ls = fullfile(proj_dir, 'scripts', 'lists', 'behavior_list.txt');
[bhvr_nm, nbhvr] = CBIG_text2cell(bhvr_ls);
for b = 1:nbhvr
    ABCD_chord_learnedBBA(fullfile(proj_dir, 'mat', 'interpretation', 'KRR', '20200719', ...
        'reg_AgeSexMtIcvPEduc_fr_y_FC_randWA', ['learned_BWAS_' bhvr_nm{b} '.mat']), ...
        fullfile(proj_dir, 'figures', 'interpretation', 'KRR', '20200721', ...
        'reg_AgeSexMtIcvPEduc_fr_y_FC_randWA', ['chord_' bhvr_nm{b}]));
end
```

## ------ KRR: regress age, sex, FD, DVARS, ICV, parental education from behaviors ------

### Test the random-WA trained model with matched WA subjects

```bash
../KRR/ABCD_KRR_test_randWAmodel_on_matchedWA.sh
```

### Compare accuracy of matched WA between models trained on whole population and trained on random WA

1. metric: predictive COD

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whiskerYA_trainAll_vs_trainXA('WA', 'WA', [], [], ...
        fullfile(proj_dir, 'mat', 'AAvsWA', 'pCOD_pass_rs_pass_pheno_reg_AgeSexMtIcvPeduc_fr_y.mat'), ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), 'predictive_COD', ...
        'Compare matched WA accuracy: whole-population trained VS random-WA trained', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), 'pCOD_matchedWA_WholePopModel_vs_randWAmodel')
    ```

2. metric: Pearson's correlation

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whiskerYA_trainAll_vs_trainXA('WA', 'WA', [], [], ...
        fullfile(proj_dir, 'mat', 'AAvsWA', 'corr_pass_rs_pass_pheno_reg_AgeSexMtIcvPeduc_fr_y.mat'), ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), 'corr', ...
        'Compare matched WA accuracy: whole-population trained VS random-WA trained', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), 'corr_matchedWA_WholePopModel_vs_randWAmodel')
    ```

3. metric: MSE

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whiskerYA_trainAll_vs_trainXA('WA', 'WA', [], [], ...
        fullfile(proj_dir, 'mat', 'AAvsWA', 'MSE_pass_rs_pass_pheno_reg_AgeSexMtIcvPeduc_fr_y.mat'), ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), 'MSE', ...
        'Compare matched WA accuracy: whole-population trained VS random-WA trained', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), 'MSE_matchedWA_WholePopModel_vs_randWAmodel')
    ```

### Test the random-WA trained model with the matched AA subjects

```bash
../KRR/ABCD_KRR_test_randWAmodel_on_matchedAA.sh
```

### Compare accuracy of matched AA between models trained on whole population and trained on random WA

1. metric: predictive COD

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whiskerYA_trainAll_vs_trainXA('WA', 'AA', [], [], ...
        fullfile(proj_dir, 'mat', 'AAvsWA', 'pCOD_pass_rs_pass_pheno_reg_AgeSexMtIcvPeduc_fr_y.mat'), ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), 'predictive_COD', ...
        'Compare matched AA accuracy: whole-population trained VS random-WA trained', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), 'pCOD_matchedAA_WholePopModel_vs_randWAmodel')
    ```

2. metric: Pearson's correlation

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whiskerYA_trainAll_vs_trainXA('WA', 'AA', [], [], ...
        fullfile(proj_dir, 'mat', 'AAvsWA', 'corr_pass_rs_pass_pheno_reg_AgeSexMtIcvPeduc_fr_y.mat'), ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), 'corr', ...
        'Compare matched AA accuracy: whole-population trained VS random-WA trained', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), 'corr_matchedAA_WholePopModel_vs_randWAmodel')
    ```

3. metric: MSE

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whiskerYA_trainAll_vs_trainXA('WA', 'AA', [], [], ...
        fullfile(proj_dir, 'mat', 'AAvsWA', 'MSE_pass_rs_pass_pheno_reg_AgeSexMtIcvPeduc_fr_y.mat'), ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), 'MSE', ...
        'Compare matched AA accuracy: whole-population trained VS random-WA trained', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), 'MSE_matchedAA_WholePopModel_vs_randWAmodel')
    ```

### Using model trained on WA, compare accuracy between matched AA and matched WA

1. metric: predictive COD

    Permutation test

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_PermTest_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), ...
        'matchedAA', 'AA', 'matchedWA', 'matchedWA', [], 'predictive_COD', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'pCOD_randWAmodel_test_matchedAAvsWA.mat'))

    % behaviors that are predictable in the whole-population model
    ABCD_KRR_PermTest_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), ...
        'matchedAA', 'AA', 'matchedWA', 'matchedWA', ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y', 'lists', 'pCOD_predictable.txt'), ...
        'predictive_COD', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'pCOD_randWAmodel_test_matchedAAvsWA_predictable_WholepopModel.mat'))
    ```

    Plotting

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whisker_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), ...
        'matchedAA', 'matchedWA', [], [], 'predictive_COD', ...
        'Matched AA vs WA (model trained on random WA)', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), ...
        'pCOD_randWAmodel_test_matchedAAvsWA', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'pCOD_randWAmodel_test_matchedAAvsWA.mat'))

    % behaviors that are predictable in the whole-population model
    ABCD_KRR_whisker_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), ...
        'matchedAA', 'matchedWA', ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y', 'lists', 'pCOD_predictable.txt'), ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y', 'lists', 'pCOD_predictable_colloquial.txt'), ...
        'predictive_COD', ...
        'Matched AA vs WA (model trained on random WA)', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), ...
        'pCOD_randWAmodel_test_matchedAAvsWA_predictable_WholepopModel', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'pCOD_randWAmodel_test_matchedAAvsWA_predictable_WholepopModel.mat'))
    ```

2. metric: Pearson's correlation

    Permutation test

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_PermTest_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), ...
        'matchedAA', 'AA', 'matchedWA', 'matchedWA', [], 'corr', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'corr_randWAmodel_test_matchedAAvsWA.mat'))

    % behaviors that are predictable in the whole-population model
    ABCD_KRR_PermTest_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), ...
        'matchedAA', 'AA', 'matchedWA', 'matchedWA', ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y', 'lists', 'corr_predictable.txt'), ...
        'corr', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'corr_randWAmodel_test_matchedAAvsWA_predictable_WholepopModel.mat'))
    ```

    Plotting

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whisker_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), ...
        'matchedAA', 'matchedWA', [], [], 'corr', ...
        'Matched AA vs WA (model trained on random WA)', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), ...
        'corr_randWAmodel_test_matchedAAvsWA', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'corr_randWAmodel_test_matchedAAvsWA.mat'))

    % behaviors that are predictable in the whole-population model
    ABCD_KRR_whisker_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), ...
        'matchedAA', 'matchedWA', ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y', 'lists', 'corr_predictable.txt'), ...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_fr_y', 'lists', 'corr_predictable_colloquial.txt'), ...
        'corr', ...
        'Matched AA vs WA (model trained on random WA)', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), ...
        'corr_randWAmodel_test_matchedAAvsWA_predictable_WholepopModel', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'corr_randWAmodel_test_matchedAAvsWA_predictable_WholepopModel.mat'))
    ```

3. metric: MSE

    Permutation test

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_PermTest_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), ...
        'matchedAA', 'AA', 'matchedWA', 'matchedWA', [], 'MSE', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'MSE_randWAmodel_test_matchedAAvsWA.mat'))
    ```

    Plotting

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whisker_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), ...
        'matchedAA', 'matchedWA', [], [], 'MSE', ...
        'Matched AA vs WA (model trained on random WA)', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), ...
        'MSE_randWAmodel_test_matchedAAvsWA', ...
        fullfile(proj_dir, 'mat', 'AAvsWA_train_subpop', 'MSE_randWAmodel_test_matchedAAvsWA.mat'))
    ```

4. metric: COD

    ```matlab
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/ABCD_race';
    ABCD_KRR_whisker_trainXA_testYAvsZA(...
        fullfile(proj_dir, 'models', 'KRR', '20200721', 'reg_AgeSexMtIcvPEduc_y_randWA'), ...
        'matchedAA', 'matchedWA', [], [], 'COD', ...
        'Matched AA vs WA (model trained on random WA)', ...
        fullfile(proj_dir, 'figures', 'randWA_trained', 'KRR', '20200721'), ...
        'COD_randWAmodel_test_matchedAAvsWA')
    ```
